package com.wenzheng.quartz.intercept;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import com.wenzheng.quartz.service.TaskItemService;

/**
 * 登录拦截器
 * @author
 * @blog
 * @version 1.0
 */
public class LoginIntercept implements HandlerInterceptor {
	@Autowired
	private TaskItemService taskItemService;

	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		HttpSession session = request.getSession();
		Object userName = session.getAttribute("login_user");
		if(userName == null) {
			// 重定向到登录
			response.sendRedirect("/login");
			return false;
		} else {
			return true;
		}
	}

	@PostConstruct
	public void init() {
		System.out.println("============ LoginIntercept init ========");
		System.out.println("============测试在 Intercept @Autowired taskItemService！ 注入结果为:" + taskItemService);
	}


}
